import os
import codecs
import string
from time import time,clock
from collections import OrderedDict,Counter

#http://www.bathome.net/thread-39926-1-2.html 合并两个大文本
ROOT_PATH = os.path.split(__file__)[0]
DIST_PATH = os.path.join(ROOT_PATH,'dist')

def getDistTxt(txtName:str):
    filePath = os.path.join(DIST_PATH,txtName)
    lines = None
    with codecs.open(filePath,'r',encoding="utf8") as f:
        #print("getDistTxt",f.read())
        lines = f.readlines()
        print("len(lines)",len(lines))
    return lines

def listToDict(lines):
    dictList = []
    for i,v in enumerate(lines):
        dictList.append(v.split()) # split的默认参数是空行也就是 \s
    od = OrderedDict(dictList)
    return od

'''
st = clock()
jdLines = getDistTxt("jd.txt")
stemLines = getDistTxt("stem.txt")
stemDict = listToDict(stemLines)
c = 0
txt = ""
txtArr = []
for i,v in enumerate(jdLines):
    arr = v.split()
    val = stemDict.get(arr[0],None)    
    if val:        
        c+=1
        tempTxt = v.strip('\r\n')+"\t"+val.strip('\r\n')+"\n"
        txt += tempTxt
        #txtArr.append(tempTxt)        
    else:
        tempTxt = v.replace("\r","")
        #txtArr.append(tempTxt)
        txt += tempTxt

#txt = "".join(txtArr)

filePath = os.path.join(DIST_PATH,"mergeJd.txt")
with open(filePath,"w",encoding="utf8") as f:
    f.write(txt)

et = clock()
ct = et-st
print(ct*1000,"ms",ct,"s")
'''


st = time()
cnt = 10000000
arr = [chr(i) for i in range(97,123)]
longStr = string.ascii_lowercase*cnt
cntMap = {key:longStr.count(key) for key in arr}
#cntMap = dict(Counter(longStr))
et = time()
print("cntMap",cntMap)
print(et-st,"second")